﻿using System;
class CustomBitInfo
{
    static void Main()
    {
        int testnumber;
        int bitposition = 0;
        Console.Write("Input Number: ");
        while (true)
        {
            try
            {
                testnumber = int.Parse(Console.ReadLine());
                break;
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message + "\nPlease re-enter test number:");
            }
        }
        Console.Write("Input Bit position: ");
        do
        {
            if (bitposition != 0)
            {
                Console.Write("Please enter correct number between 0 and 32: ");
            }
            while (true)
            {
                try
                {
                    bitposition = int.Parse(Console.ReadLine());
                    break;
                }
                catch (Exception ex)
                {
                    Console.Write(ex.Message + "\nPlease re-enter position:");
                }
            }
        } while ((bitposition < 0) || (bitposition > 32));
        Console.WriteLine(Convert.ToString(testnumber, 2).PadLeft(32, '0'));
        Console.ReadLine();
        bool isbitone = (((testnumber & (1 << bitposition)) >> bitposition) == 1);
        Console.WriteLine("the bit {0} is 1? {1}",bitposition, isbitone);
        Console.ReadLine();
    }
}

